package com.example.demospring.controller.assistant;

import com.example.demospring.dto.assistant.ConsultationRecordDTO;
import com.example.demospring.service.assistant.ConsultationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/consultation/records")
public class ConsultationRecordController {

    @Autowired
    private ConsultationRecordService recordService;

    // 分页查询&支持条件
    @GetMapping
    public Page<ConsultationRecordDTO> list(
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) String status,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        return recordService.findPage(keyword, status, page, size);
    }

    // 查详情
    @GetMapping("/{id}")
    public ConsultationRecordDTO getById(@PathVariable Integer id) {
        return recordService.getById(id);
    }

    // 新建/更新
    @PostMapping
    public ConsultationRecordDTO save(@RequestBody ConsultationRecordDTO dto) {
        return recordService.saveOrUpdate(dto);
    }

    // 删除
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        recordService.delete(id);
    }
}
